//
//  YTStashForewarningDetailsViewController.m
//  YuTang
//
//  Created by 葛悦彣 on 2024/11/15.
//

#import "YTStashForewarningDetailsViewController.h"
#import "YTStashForewarningModel.h"
#import "YTStashForewarningDetailsHeaderview.h"
#import "YTStashForewarningDetailsTableViewCell.h"

@interface YTStashForewarningDetailsViewController ()
@property (nonatomic ,strong) YTStashForewarningModel * model;
@end

@implementation YTStashForewarningDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.NoDataHidden = YES;
    UIView * topview = [UIView new];
    topview.backgroundColor = KcolorHex(@"#0967FF");
    [self.view addSubview:topview];
    [topview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.offset(0);
        make.height.offset(Knav_HeightX);
    }];
    MJWeakSelf
    UIView * backview = [UIView new].addClickBlock(^{
        [weakSelf popViewController];
    });
    [topview addSubview:backview];
    [backview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.offset(44);
        make.left.bottom.offset(0);
        make.width.offset(kwt(170));
    }];
    
    UIImageView * leftimg = kimageView(@"white_path");
    [backview addSubview:leftimg];
    [leftimg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(20);
        make.left.offset(kwt(10));
        make.centerY.offset(0);
    }];
    
    UILabel * leftlab = [DTKTool labelWithText:@"预警记录" andFont:kCFont(19) andTextColor:UIColor.whiteColor];
    [backview addSubview:leftlab];
    [leftlab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(43));
        make.centerY.offset(0);
    }];
    
    
    
    [self.view addSubview:self.tableview];
    [self.tableview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.offset(0);
        make.top.equalTo(topview.mas_bottom);
    }];
    [self loadNewData];
}
- (void)loadNewData{
    [self.view showBusyHUD];
    NSMutableDictionary * dict = [NSMutableDictionary dictionary];
    [dict setObject:self.ID forKey:@"id"];
    [SCNetManger warehouseAlarmGetAlarmDetailWithDict:dict andCompetionHandlerBlock:^(HTTPDicBase * model) {
        [self.view hideBusyHUD];
        if(model.code == 200){
            self.model = [YTStashForewarningModel yy_modelWithDictionary:model.result];
            [self.tableview reloadData];
        } else {
            [self.view showWarning:model.message];
        }
    }];
}


-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    YTStashForewarningDetailsHeaderview * headerview = [YTStashForewarningDetailsHeaderview initview];
    headerview.model = self.model;
    return headerview;
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if(self.model){
        return self.model.HeaderViewH - kwt(16) - self.model.expiratDateH;
    }
    return 0;
}

- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return  1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return self.model.DetailsCellH;
}

- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    
    
    YTStashForewarningDetailsTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"YTStashForewarningDetailsTableViewCell"];
    if (cell == nil) {
        cell = [[YTStashForewarningDetailsTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"YTStashForewarningDetailsTableViewCell"];
    }
    cell.model = self.model;

    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell ;
    
}
@end
